import java.util.*;

/*
public class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}*/
public class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        // write code here
        ListNode fast=A;
        ListNode slow=A;
        while(fast!=null&&fast.next!=null){
            fast=fast.next.next;
            slow=slow.next;
        }
        ListNode reversed = reverse(slow);
        while(A!=null&&reversed!=null){
            if(A.val!=reversed.val){
                return false;
            }else
                reversed=reversed.next;
            A=A.next;
        }
        return true;
    }
    public ListNode reverse(ListNode A){
        if(A==null) return null;
        ListNode n0=null;
        ListNode n1=A;
        ListNode n2=A.next;
        while(n1!=null){
            n1.next=n0;
            n0=n1;
            n1=n2;
            if(n2!=null){
                n2=n2.next;
            }
        }


        return n0;

    }
}